/*
 * @Description:token key
 * @Version: 2.0
 * @Autor: kafei
 * @Date: 2021-11-19 10:37:54
 * @LastEditors: kafei
 * @LastEditTime: 2021-11-19 15:28:22
 */

const key = 'zzsswwdcvbeq'
const jsonwebtoken = require('jsonwebtoken')

const handleTokenData = (data) => {
  const target = Object.assign({}, data)
  console.log(target, 'target')
  const info = {
    Bearer: 'Bearer ',
    // 签发 token，1天
    token: jsonwebtoken.sign(
      target,
      key,
      { expiresIn: '1d' }
    )
  }
  return info
}
const getJWTPayload = (token) => {
  return jsonwebtoken.verify(token.split(' ')[1], key)
}
module.exports = {
  handleTokenData,
  key,
  getJWTPayload
}
